package org.jackysoft.struts2.admin;

import java.util.Collection;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Namespace;
import org.jackysoft.annotations.Logger;
import org.jackysoft.entity.AcegiRole;
import org.jackysoft.entity.Department;
import org.jackysoft.entity.User;
import org.jackysoft.service.UserService;
import org.jackysoft.struts2.UtilsCRUDAction;
import org.jackysoft.util.OperationType;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.google.common.collect.Lists;


@Controller
@Namespace("/admin/user")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Logger(label="用户",logType=OperationType.System)
public class UserAction extends UtilsCRUDAction<User> {

	private User bean;
	private Collection<User> beans;
	private UserService service;
	private AcegiRole acegi;
	private Department department;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	

	public String byacegi() throws Exception{
		Collection<AcegiRole> auths = Lists.newLinkedList();
		auths.add(acegi);
		this.searchMap.clear();
		this.searchMap.put("authoritys", auths);
		getJson();
		return JQGRID;
	}
	
	
	public String acegi()throws Exception{
		return SUCCESS;
	}
	

	public String samedept() throws Exception{
		beans = service.getsBySameDepartment();
		return BEANLIST;
	}
	
	

	public String saveprofile() throws Exception{
	    service.saveProfile(bean);
		return SUCCESS;	
	}
	

	
	public String bydepartment() throws Exception{
	    pager = service.gets(department,page,rows);
		return JQGRID;
	}
	

	public String search() throws Exception {
		beans = service.searchs(getSearch());
		return BEANLIST;
	}
	
	
	
	public UserService getService() {
		return service;
	}

	@Resource
	public void setService(UserService service) {
		this.service = service;
		this.setDataProvider(service);
	}

	public User getBean() {
		return bean;
	}

	public void setBean(User bean) {
		this.bean = bean;
	}

	public Collection<User> getBeans() {
		return beans;
	}

	public void setBeans(Collection<User> beans) {
		this.beans = beans;
	}



	public AcegiRole getAcegi() {
		return acegi;
	}



	public void setAcegi(AcegiRole acegi) {
		this.acegi = acegi;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}	
}